import {Result} from '@/base/Result';
import {request} from '@/base/Request';
import {Page} from '@/base/Page';
import {Lv} from '@/base/model/Lv';
import qs from 'qs'
import {Category} from '@/base/model/Category';
import {Model} from '@/base/model/Model';
import {Product} from '@/base/model/Product';
import {Gift} from '@/base/model/Gift';
import {ProductCategory} from '@/base/model/ProductCategory';
import {Color} from '@/base/model/Color';
import {DeviceModel} from "@/base/model/DeviceModel";

export function getLvList(params: {
  pageIndex: number,
  pageSize: number,
  sortDirection?: string,
}): Promise<Result<Page<Lv>>> {
  return request.getPage(Lv, '/api/member-level/fetchLv', {params});
}
export function getCategoryList(): Promise<Result<Page<Category>>> {
  return request.getData(Category, '/api/member-level/getCategory');
}
export function getCategoryExList(): Promise<Result<Page<Category>>> {
  return request.getData(Category, '/api/member-level/getCategoryV2');
}
export function getModelList(params:{categoryId}): Promise<Result<Page<Model>>> {
  return request.getData(Model, '/api/member-level/getModel', {params});
}
export function getProductModelList(params:{
  productName?: string,
}): Promise<Result<Page<Model>>> {
  return request.getProcutModelData(Model, '/api/member-level/searchModel', {params});
}
export function getProductList(params:{
  categoryId?

  productName?
  pageIndex?
  pageSize?
  sortDirection?
}): Promise<Result<Page<Product>>> {
  return request.getData(Product, '/api/member-level/getProduct', {params});
}
export function getProductListByCategory(params:{
  modelId: number
}): Promise<Result<Page<Product>>> {
  return request.getData(Product, '/api/member-level/getProduct', {params});
}
export function getProductAll(params:{
}): Promise<Result<Page<Product>>> {
  return request.getData(Product, '/api/member-level/getProduct', {params});
}
export function getProductId(params: {
  id: number
}) {
  return request.get(Product, '/api/device-model/{id}'.replace('{id}', params.id.toString()));
}
export function PutProductId(params: {
  productId: number,
  status: number,
  sym:number
}) {
  return request.put(Product, `/api/banner/${params.productId}`, qs.stringify(params))
}
export function getProductCategoryList(params:{
  pageIndex?
  pageSize?
  sortDirection?
}): Promise<Result<Page<ProductCategory>>> {
  return request.getData(ProductCategory, '/api/member-level/getProduct', {params});
}

export function getProductColorList(params:{
  pageIndex?
  pageSize?
  sortDirection?
}): Promise<Result<Page<Color>>> {
  return request.getData(Color, '/api/member-level/getProduct', {params});
}
// 删除产品
export function deleteProduct(params: {
  id: number
}) {
  return request.delete('/api/device-model/{id}'.replace('{id}', params.id.toString()));
}
// 删除产品分类
export function deleteCategory(params: {
  id: number
}) {
  return request.delete('/api/device-sort/{id}'.replace('{id}', params.id.toString()));
}
// 移动分类排序
export function putCategorySort(params: {
  id: []
}) {
  return request.put(ProductCategory, '/api/device-sort/sort', qs.stringify(params, {arrayFormat: 'repeat'}));
}
// 新增产品分类
export function postCategory(params: {
  id?,
  sortName: string,
  sortState: number
  sortIcon:string
}) {
  return request.post(ProductCategory, '/api/device-sort', qs.stringify(params));
}

export function getGiftList(lv: number): Promise<Result<Gift>> {
  return request.get(Gift, `/api/member-level/${lv}`);
}

export function putlv(params: {
  lv : number,
  upgradeCondition: number,
  name: string,
  upgradeGift: number,
  upgradePoint: number,
  memberCard:string,
  sortName: string,
  modelName: string,
  productNumber: string,
  num: number,
  imgUrl: string
}) {
  return request.put(Lv, '/api/member-level/updateLv', qs.stringify(params));
}
// 添加商品
export function postProduct(params: {
  modelId: number,
  categoryId: number,
  colorId: number,
  price: number,
  point: number,
  banners: string,
  detail: string
}) {
  return request.post(Product, '/api/device-model', qs.stringify(params));
}
 // 编辑商品
export function putProduct(params: {
  id: number,
  modelId: number,
  categoryId: number,
  colorId: number,
  price: number,
  point: number,
  banners: string,
  detail: string
}) {
  return request.put(Product, '/api/device-model/{id}'.replace('{id}', params.id.toString()), qs.stringify(params));
}
